import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
 * @author wcj
 * @Date 2021/6/17 15:23
 * @Version 1.0
 */
public class AtomicIntegerFieldTest {

    public static void main(String[] args) {
        AtomicIntegerFieldUpdater<Person> age = AtomicIntegerFieldUpdater.newUpdater(Person.class, "age");
        Person wcj = new Person("wcj", 25);
        System.out.println(age.getAndIncrement(wcj));
        System.out.println(age.get(wcj));
    }

}

class Person {

    private String name;
    public volatile int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}
